package es.mgil.linternas;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class LinternaPoliciaBis extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);

		setContentView(new LinternaPoliciaView(this));
	}

	private class LinternaPoliciaView extends View {
		private Paint paint;
		private int blueColor = 0xff0000ff;
		private int redColor = 0xffff0000;
		private boolean upperBlue;

		public LinternaPoliciaView(Context context) {
			super(context);
			paint = new Paint();
			upperBlue = true;
		}

		@Override
		protected void onDraw(Canvas canvas) {
			// draw the background color
			canvas.drawRGB(255, 255, 255);

			{
				// upper rectangle
				paint.setStyle(Style.FILL);
				if (upperBlue) {
					paint.setColor(blueColor);
				} else {
					paint.setColor(redColor);
				}
				canvas.drawRect(0, 0, canvas.getWidth(),
						canvas.getHeight() / 2, paint);
			}

			{
				// lower rectangle
				paint.setStyle(Style.FILL);
				if (upperBlue) {
					paint.setColor(redColor);
				} else {
					paint.setColor(blueColor);
				}
				canvas.drawRect(0, canvas.getHeight() / 2, canvas.getWidth(),
						canvas.getHeight(), paint);
			}

			upperBlue = !upperBlue;

			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
			} finally {
				invalidate();
			}
		}
	}
}
